using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;
using Mimi.Common;
using Mimi.ViewModels;

namespace Mimi.Locator
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// </summary>
    public class ViewModelLocator
    {
        #region Methods
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            //Register ViewModel
            RegisterViewModel();
        }

        /// <summary>
        /// This method register ViewModels to SimpleIOC that helps app to manage instances of viewmodels
        /// </summary>
        private static void RegisterViewModel()
        {
            SimpleIoc.Default.Register<IMainWindowViewModel, MainWindowViewModel>();
            SimpleIoc.Default.Register<IExpenseViewModel, ExpenseViewModel>();
            SimpleIoc.Default.Register<IOverviewViewModel, OverviewViewModel>();
            SimpleIoc.Default.Register<IBudgetViewModel, BudgetViewModel>();
            SimpleIoc.Default.Register<IFilterViewModel, FilterViewModel>();

            SimpleIoc.Default.Register<IStorageManager, StorageManager>();
        }
        
        /// <summary>
        /// Clean up viewModels
        /// </summary>
        public static void Cleanup()
        {
            // TODO Clear the ViewModels
        }
        #endregion

        #region Properties
        /// <summary>
        /// Returns instance of ExpenseViewModel
        /// </summary>
        public IExpenseViewModel ExpenseViewModel
        {
            get { return ServiceLocator.Current.GetInstance<IExpenseViewModel>(); }
        }

        /// <summary>
        /// Returns instance of MainWindowViewModel
        /// </summary>
        public IMainWindowViewModel MainWindowViewModel
        {
            get { return ServiceLocator.Current.GetInstance<IMainWindowViewModel>(); }
        }

        /// <summary>
        /// Returns instance of OverviewViewModel
        /// </summary>
        public IOverviewViewModel OverviewViewModel
        {
            get { return ServiceLocator.Current.GetInstance<IOverviewViewModel>(); }
        }

        /// <summary>
        /// Returns instance of StorageManager
        /// </summary>
        public IStorageManager StorageManager
        {
            get { return ServiceLocator.Current.GetInstance<IStorageManager>(); }
        }

        /// <summary>
        /// Returns instance of BudgetViewModel
        /// </summary>
        public IBudgetViewModel BudgetViewModel
        {
            get { return ServiceLocator.Current.GetInstance<IBudgetViewModel>(); }
        }

        /// <summary>
        /// /// <summary>
        /// Returns instance of FilterViewModel
        /// </summary>
        /// </summary>
        public IFilterViewModel FilterViewModel
        {
            get { return ServiceLocator.Current.GetInstance<IFilterViewModel>(); }
        }
        #endregion
    }
}